﻿using System.Collections.Generic;
using System.ComponentModel;
using GIMS.Def.Settings;
using GIMS.GUI.ArgumentControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using GIMS.Def.Arguments;

namespace GIMS.GUI.Test
{
    /// <summary>
    ///This is a test class for DrawArgumentControlViewModelTest and is intended
    ///to contain all DrawArgumentControlViewModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DrawArgumentControlViewModelTest
    {
        /// <summary>
        /// Reset GlobalSettings
        /// </summary>
        [TestInitialize()]
        public void MyTestInitialize()
        {
            GlobalSettings_Accessor.instance = null;
        }

        /// <summary>
        ///A test for IsText and IsNotText
        ///</summary>
        [TestMethod()]
        public void IsTextTest()
        {
            DrawArgument drawArgument = new DrawArgument();
            DrawArgumentControlViewModel target = new DrawArgumentControlViewModel(drawArgument);
            drawArgument.Shape = Shape.line;
            Assert.IsFalse(target.IsText);
            Assert.IsTrue(target.IsNotText);
            drawArgument.Shape=Shape.text;
            Assert.IsTrue(target.IsText);
            Assert.IsFalse(target.IsNotText);
        }

        /// <summary>
        ///A test for ShapeRepresenter Property
        ///</summary>
        [TestMethod()]
        public void ShapeRepresenterTest()
        {
            DrawArgument drawArgument = new DrawArgument();
            DrawArgumentControlViewModel target = new DrawArgumentControlViewModel(drawArgument);
            IEnumerable<ShapeRepresenter> shapes=target.ShapeRepresenters;
            ShapeRepresenter s1 = shapes.First();
            Assert.IsTrue(s1.Name.Equals("line"));
            Assert.IsTrue(s1.Value==Shape.line);
            ShapeRepresenter s2 = shapes.Last();
            Assert.IsTrue(s2.Name.Equals("text"));
            Assert.IsTrue(s2.Value == Shape.text);
        }

        /// <summary>
        ///A test for DrawArgument_PropertyChanged. Raised by changing the Shape.
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.Def.dll")]
        public void DrawArgument_PropertyChangedTest()
        {
            DrawArgument argument = new DrawArgument();
            argument.Shape = Shape.line;
            DrawArgumentControlViewModel viewModel = new DrawArgumentControlViewModel(argument);

            List<string> receivedEvents = new List<string>();
            viewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };
            argument.Shape=Shape.text;
            Assert.AreEqual(2, receivedEvents.Count);
        }
    }
}
